package com.wonderful.mall.member.web;

import com.alibaba.fastjson.JSON;
import com.wonderful.common.utils.R;
import com.wonderful.mall.member.constant.OrderStatusEnum;
import com.wonderful.mall.member.feign.OrderFeignService;
import com.wonderful.mall.member.vo.PayRespVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {
    @Resource
    OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(PayRespVo payRespVo, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, Model model) {
        if (payRespVo.getOut_trade_no()!=null){
            String orderSn = payRespVo.getOut_trade_no();
            R r = orderFeignService.modifyOrderStatus(orderSn, OrderStatusEnum.PAYED.getCode());
            System.out.println(r);
        }
        //查出当前登录的用户的所有订单列表数据
        Map<String, Object> page = new HashMap<>();
        page.put("page", pageNum.toString());
        R r = orderFeignService.listWithItem(page);
        System.out.println(JSON.toJSONString(r));
        model.addAttribute("orders", r);
        return "orderList";
    }
}
